package com.tyc.design;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 类描述
 *
 * @author tyc
 * @version 1.0
 * @date 2023-03-07 11:22:23
 */
public class ReportManagerFactory {
    Map<String,FinancialReportManager> financialReportManagerMap = new ConcurrentHashMap<>();
    Map<String,EmployeeReportManager> employeeReportManagerMap = new ConcurrentHashMap<>();

    IReportManager getFinancialReportManager(String tenantId){
        //通过租户ID获取享元
        FinancialReportManager r = financialReportManagerMap.get(tenantId);
        if(r == null){
            // 没有则创建并进行维护
            r=new FinancialReportManager(tenantId);
            financialReportManagerMap.put(tenantId,r);
        }
        return r;
    }

    IReportManager getEmployeeReportManager(String tenantId){
        EmployeeReportManager r = employeeReportManagerMap.get(tenantId);
        if(r == null){
            r=new EmployeeReportManager(tenantId);
            employeeReportManagerMap.put(tenantId,r);
        }
        return r;
    }

    public static void main(String[] args) {
        ReportManagerFactory rmf=new ReportManagerFactory();
        IReportManager rm=rmf.getFinancialReportManager("A");
        System.out.println(rm.createReport());
    }
}
